package com.qf.myapplicationqqqqqqqqqqqqqqqqqq;

import android.app.Activity;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.View;
import android.widget.EditText;
import android.widget.Toast;

import com.hyphenate.chat.EMClient;
import com.hyphenate.exceptions.HyphenateException;

public class RegistActivity extends Activity {
  private EditText mEditname;
  private EditText mEditPass1;
  private EditText mEditPass2;
    private Handler mhandler=new Handler(){
        @Override
        public void handleMessage(Message msg) {
            super.handleMessage(msg);
            int what=msg.what;
            switch (what){
                case 998:
                    Toast.makeText(RegistActivity.this,"这是图斯",Toast.LENGTH_SHORT).show();
                    break;
            }
        }
    };
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_regist);
        mEditname= (EditText) findViewById(R.id.reg_account);
        mEditPass1= (EditText) findViewById(R.id.reg_password);
        mEditPass2= (EditText) findViewById(R.id.reg_password_confirm);
    }

    public void BTNregistONclick(View view) {
     final   String name=mEditname.getText().toString().trim();
        final  String p1=mEditPass1.getText().toString().trim();
        final String p2=mEditPass2.getText().toString().trim();
        if (name.length()>3&&p1.length()>3&&p1.equals(p2)){
            //注册账号
            Thread thread=new Thread(){
                @Override
                public void run() {
                    try {
                        //只要方法不抛异常 注册成功
                        EMClient.getInstance().createAccount(name,p1);//同步代码

                  Message message=mhandler.obtainMessage(998);
                        mhandler.sendMessage(message);

                    } catch (HyphenateException e) {
                        e.printStackTrace();
                    }


                }
            };
           thread.start();
        }

    }
}
